home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / arc / AmySTP16c_src.lha / AmyStpEncoder.c < prev    next >
C/C++ Source or Header  |  1997-06-05  |  5KB  |  157 lines

  1. /* **************************************************************
  2.    *                                *
  3.    *                    STP Encoder Program                     *
  4.    *                                *
  5.    *  Original version by: Mnp (unknown)                        *
  6.    *  Amiga (optimized) version by: Manolis S Pappas            *
  7.    *                                Thermopilon 24              *
  8.    *                    14231 Nea Ionia        *
  9.    *                    Athens GREECE        *
  10.    *                                *
  11.    *  E-mail:                            *
  12.    *        mpappas@posidon.servicenet.ariadne-t.gr     *
  13.    *            mpappas@acropolis.net                           *
  14.    *        2:410/128.19                    *
  15.    *        39:250/3.19                    *
  16.    **************************************************************
  17. */
  18. /* Version 1.6c */
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <dos.h>        /* WARNING: Needed for SPECIFIC SAS/C function */
  25.  
  26. #define false(a) (((a)<32)||(((a)>123) && ((a)<179))||((a)>216))
  27. #define R_MARGIN 65
  28.  
  29. #define VERSION "1.6c"
  30. static const char CLI_VERS[]="$VER: AmySTP Encoder v1.6c "__AMIGADATE__;
  31.  
  32.  int err(int e)
  33.  {
  34.     char *errlist[12];
  35.  
  36.     errlist[0]="Cannot open input file";
  37.     errlist[1]="Cannot create output file";
  38.     errlist[3]="Cannot open input file";
  39.     errlist[7]="Cannot create output file";
  40.     errlist[9]="Internal error";
  41.  
  42.    fprintf("Error(%d): %s\n",e,errlist[e-2]);
  43.    return e;
  44.  }
  45.  
  46.  
  47.  main(int argc,char *argv[])
  48.  {
  49.      FILE *fin, *fout;
  50.      unsigned char z=R_MARGIN,x,n=7,i,j,a,b[7],c[8],terminate=0;
  51.      unsigned int part=1,sum=1,l;
  52.      unsigned long checksum=0,fsize=0,chars=0,newsum=0;
  53.      char s[80]="";
  54.      char *string[5], *point=".";
  55.      char drive[FNSIZE],path[FMSIZE],node[FNSIZE],ext[FESIZE]; /* WARNING: SAS/C specific function's variables */
  56.    /* NOTE: Fxxxx variables are TOTALLY AMIGA SPECIFIC */
  57.            
  58.  string[0]="START STP SCRIPT %u OF %u\n";
  59.  string[1]="FILENAME : %s - FILESIZE : %lu\n";
  60.  string[2]="CHARACTERS : %lu - CHECKSUM : %lX\n";
  61.  string[3]="\nEND STP SCRIPT\n";
  62.  string[4]="Successful. Checksum :";
  63.  
  64.  if (argc<3)
  65.     {
  66.            fprintf(stderr,"\nAmySTP Binary Mail Encoder "__AMIGADATE__
  67.                   ".\nCopyright © 1994-97, Infinity Labs Development. All Rights Reserved.\n"
  68.                   "Author: Manolis S Pappas. Version: %s\n",VERSION);
  69.            fprintf(stderr,"\nUsage: %s [binary input file] [output text file] {-d=[right margin]}\n",argv[0]);
  70.    
  71.    exit(1);
  72.     }
  73.  
  74.    if ((fin=fopen(argv[1],"rb"))==NULL) exit(err(2));
  75.  
  76.    if ((fout=fopen(argv[2],"w"))==NULL) exit(err(3));
  77.  
  78.     if (argc>3)
  79.     {
  80.         
  81.     for (i=3;i<argc;i++)
  82.         {
  83.             if (strstr(argv[i],"-d="))
  84.             {
  85.                 z=(char)atoi(argv[i]+=3);
  86.                 if ((z<10)||(z>78))
  87.                 {
  88.                     fprintf(stderr,"Right margin must be in the range of 10..78.\n"
  89.                                    "Using default right margin (65) ...\n");
  90.                     z=R_MARGIN;
  91.                 }
  92.                 else fprintf(stderr,"Right margin will be : %u\n",z);
  93.             }
  94.         }
  95.         for (i=3;i<argc;i++)
  96.         {
  97.             /*
  98.             if (strstr(argv[i],"-l="))
  99.             {
  100.                 l=atoi(argv[i]+=3);
  101.                 fprintf(stderr,"Suggested output file length : %u\n",l);
  102.         }
  103.              */
  104.         }
  105.     }
  106.  
  107.     x=z-1;
  108.     a=getc(fin);
  109.     while(!feof(fin))
  110.     {
  111.         fsize++;
  112.         checksum+=a;
  113.         a=getc(fin);
  114.     }
  115.     chars=(fsize/7)*8+(fsize%7)+1*(fsize%7!=0);
  116.     
  117.     strsfn(argv[1],drive,path,node,ext); /* WARNING: SAS/C specific function: split complete pathargument into portions (name,drive,path,node,ext) */
  118.     
  119.     if((stcgfe(ext,argv[1]))!=0){ /* WARNING: Another SAS/C specific function: stcgfe */
  120.         strcat(node, point);
  121.         strcat(node, ext);
  122.     }
  123.     fprintf(fout,string[0],part,sum);
  124.     fprintf(fout,string[1],node,fsize);
  125.     fprintf(fout,string[2],chars,checksum);
  126.  
  127.     rewind(fin);
  128.     b[0]=getc(fin);
  129.     while (!feof(fin))
  130.    {
  131.         for (i=1;i<7;i++)
  132.         {
  133.             b[i]=getc(fin);
  134.             if (feof(fin)) b[i]=0;
  135.         }
  136.                 c[0]=(b[0]>>1);
  137.                 c[1]=((b[0]& 1)<<6)|(b[1]>>2);
  138.                 c[2]=((b[1]& 3)<<5)|(b[2]>>3);
  139.                 c[3]=((b[2]& 7)<<4)|(b[3]>>4);
  140.                 c[4]=((b[3]&15)<<3)|(b[4]>>5);
  141.                 c[5]=((b[4]&31)<<2)|(b[5]>>6);
  142.                 c[6]=((b[5]&63)<<1)|(b[6]>>7);
  143.                 c[7]=(b[6]&127);
  144.         for (i=0;i<8;i++)
  145.         {
  146.             putc(c[i]<91?33+c[i]:89+c[i],fout);
  147.             if (!(--chars)) break;
  148.             if (!(x--||feof(fin))) { fprintf(fout,"\n");x=z-1; }
  149.         }
  150.         b[0]=getc(fin);
  151.     }
  152.     fprintf(fout,string[3]);
  153.     fclose(fin); fclose(fout);
  154.     fprintf(stderr,"File encoding %s %lX\n", string[4], checksum);
  155.     return 0;
  156.  }
  157.